package com.galen.wxRead.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.galen.wxRead.bean.RetBaseVo;
import com.galen.wxRead.domain.ReadInfo;
import com.galen.wxRead.domain.ReadWx;
import com.galen.wxRead.server.OpenApiServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class openApiController {

    @Autowired
    private OpenApiServer openApiServer;

    @PostMapping("/getReadWx")
    public RetBaseVo getReadWx() {
        RetBaseVo retBaseVo = openApiServer.getReadWx();
        return retBaseVo;
    }

    @PostMapping("/addOrderList")
    public RetBaseVo addOrderList(@RequestBody List<JSONObject> readInfoList){
        return openApiServer.addOrderList(readInfoList);
    }

    @GetMapping("/getOrder")
    public RetBaseVo getOrder(@RequestParam int taskId) {
        return openApiServer.getOrder(taskId);
    }

    @PostMapping("/addReadTask")
    public RetBaseVo addReadTask(@RequestBody String json) {
        JSONObject jsonObject = JSON.parseObject(json);
        String url = jsonObject.getString("url");
        int taskNum = jsonObject.getInteger("taskNum");
        int initNum = jsonObject.getInteger("initNum");
        return openApiServer.addReadTask(url, taskNum, initNum);
    }

    @PostMapping("/updateReadTask")
    public RetBaseVo updateReadTask(@RequestBody String json) {
        JSONObject jsonObject = JSON.parseObject(json);
        long id = jsonObject.getLong("id");
        int taskNum = jsonObject.getInteger("taskNum");
        int initNum = jsonObject.getInteger("initNum");
        return openApiServer.updateReadTask(id, taskNum, initNum);
    }

    @PostMapping("/getOrderList")
    public RetBaseVo getOrderList(@RequestBody ReadInfo readInfo) {
        return openApiServer.getOrderList(readInfo);
    }

    @GetMapping("/delOrder")
    public RetBaseVo delOrder(@RequestParam int taskId) {
        return openApiServer.delOrder(taskId);
    }

    @GetMapping("/bitchDelOrder")
    public RetBaseVo bitchDelOrder(){
        return openApiServer.bitchDelOrder();
    }

    @GetMapping("/setReadWxStatus")
    public RetBaseVo setReadWxStatus(@RequestParam int type){
        return openApiServer.setReadWxStatus(type);
    }

    @GetMapping("/getReadWxStatus")
    public int getReadWxStatus(){
        return openApiServer.getReadWxStatus();
    }

    @GetMapping("/setReadWxLimit")
    public RetBaseVo setReadWxLimit(@RequestParam int num){
        return openApiServer.setReadWxLimit(num);
    }

    @GetMapping("/getReadWxLimit")
    public int getReadWLimit(){
        return openApiServer.getReadWxLimit();
    }
}
